import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: "/index",
    name: "index",
    component: () => import('../views/index.vue'),
    children: [
      {
        path: "/addDish",
        name: "addDish",
        component: () => import('../views/addDish.vue'),
      },
      {
        path: "edit/:id",
        name: "edit",
        component: () => import('../views/addDish.vue'),

      },
      {
        path: "/showDish",
        name: "showDish",
        component: () => import('../views/showDish.vue'),
      },
      {
        path: "/index",
        name: "statement",
        component: () => import('../views/statement.vue'),
      }
    ]
  }
  // {
  //   path: '/about',
  //   name: 'About',

  //   component: () => import('../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  console.log(to.path);
  if (to.path === '/') {
    next();
  } else {
    //
    let nickName = sessionStorage.getItem('nickName');

    if (nickName === null || nickName === '') {
      next('/');
    } else {
      next();
    }
  }
});
export default router